<?php
namespace app\admin\controller;
use app\service\roominfoService;
use think\facade\Db;
use think\facade\View;

class Reimburse extends Common{
	public function reimburseList(){
		$com = $this->pidTokenId();
		$whe['community_id'] = array('in',$com['community_id']);
		$communitylist=(new roominfoService())->communityList($whe);
		View::assign('communitylist',$communitylist);
		$reimburselist=Db::table("v2_reimburse")->where($whe)->order("id desc")->select()->toArray();
		View::assign("list",$reimburselist);
		return View::fetch("v2_reimburse/reimburse_list");
	}

	public function reimburseAdd(){
		$com = $this->pidTokenId();
		if(request()->isPost()){
			$data=request()->post();
			$community=Db::name('community')->where('community_id',$data["community_id"])->find();
			$data["reimburse_time"]=strtotime($data["reimburse_time"]);
			$data["community_name"]=$community["community_name"];
			$data["create_time"]=time();
			$res=Db::table("v2_reimburse")->insert($data);
           	if($res){
           		
                $this->success('新增报销成功',url('reimburseAdd'));
            }else{
                $this->error('新增报销成功',url('reimburseAdd'));
            }
		}else{
			$whe['community_id'] = array('in',$com['community_id']);
			$communitylist=(new roominfoService())->communityList($whe);
			View::assign('communitylist',$communitylist);
			return View::fetch("v2_reimburse/reimburse_add");
		}
	}
}